var e = require("../../@babel/runtime/helpers/toConsumableArray"), a = getApp();

Page({
    data: {
        activeName: 1,
        slideDown: !1,
        selectedTime: "",
        currentDate: new Date().getTime(),
        minDate: new Date(2020, 0, 1).getTime(),
        currentTime: "",
        sale: [],
        salesDetail: [],
        page: 1,
        orderLastPage: !1
    },
    onLoad: function(e) {},
    onReady: function() {},
    onShow: function() {
        this.setData({
            currentTime: this.timestampToTime(new Date().getTime())
        }), this.getData(this.data.currentTime);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (this.data.orderLastPage) console.log("没有更多了"); else {
            var e = this.data.page;
            e++, this.setData({
                page: e
            }), this.getData(this.data.currentTime, "more");
        }
    },
    goMy_team_sales: function() {
        wx.navigateTo({
            url: "/packageI/group_sales/my_team_sales/my_team_sales"
        });
    },
    timeToScreen: function(e) {
        var a = e.detail;
        this.setData({
            selectedTime: this.timestampToTime(a)
        }), this.getData(this.timestampToTime(a)), this.changeSlideDown();
    },
    changeSlideDown: function() {
        this.setData({
            slideDown: !this.data.slideDown
        });
    },
    cancelTimePopover: function() {
        this.setData({
            slideDown: !1
        });
    },
    onInput: function(e) {
        this.setData({
            currentDate: e.detail
        });
    },
    timestampToTime: function(e) {
        var a = new Date(e);
        return a.getFullYear() + "-" + (a.getMonth() + 1 < 10 ? "0" + (a.getMonth() + 1) : a.getMonth() + 1);
    },
    getData: function(t, s) {
        var n = this;
        t = parseInt(t.replace("-", "")), "more" != s && this.setData({
            page: 1
        });
        var i = a.getNetAddresss("plugin.agent-earnings.frontend.sales-statistical.get-sales-list");
        a._postNetWork({
            url: i,
            data: {
                month_str: t,
                page: this.data.page
            },
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    var i, o, l = n.data.sale;
                    if (l[0] = t.data.current_month_sales, l[1] = t.data.annual_sales, n.setData({
                        orderLastPage: !1
                    }), t.data.list.current_page >= t.data.list.last_page && n.setData({
                        orderLastPage: !0
                    }), n.setData({
                        agentLevel: t.data.agent_info.has_one_level.level_name,
                        username: t.data.agent_info.has_one_member.username,
                        avatar_image: t.data.agent_info.has_one_member.avatar_image,
                        sale: l
                    }), "more" == s) n.setData({
                        salesDetail: [].concat(e(n.data.salesDetail), e(null === (i = t.data.list) || void 0 === i ? void 0 : i.data))
                    }); else n.setData({
                        salesDetail: null === (o = t.data.list) || void 0 === o ? void 0 : o.data
                    });
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    onShareAppMessage: function() {}
});